﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Lib
{
    public class LogFileInfo
    {
        public long FileOffset { get; private set; }
        public int Length { get; private set; }

        private readonly FileInfo _informationProvider;
        private long _fileSize;

        public LogFileInfo(string fullPath)
        {
            _informationProvider = new FileInfo(fullPath);
            _fileSize = _informationProvider.Length;
        }

        public LogFileInfo(string fullPath, long fileSize)
        {
            _informationProvider = new FileInfo(fullPath);
            _fileSize = 0;
        }

        public bool HasChanged
        {
            get 
            {
                // Get
                _informationProvider.Refresh();
                if(_fileSize == _informationProvider.Length)
                    return false;

                // Project
                FileOffset = _fileSize;
                Length = (int)(_informationProvider.Length - _fileSize);

                // Set
                _fileSize = _informationProvider.Length;

                return true;
            }
        }

        public string FullPath
        {
            get { return _informationProvider.FullName; }
        }
    }
}
